<?php
include('global.php');	//引入全局主文件
$GLOBALS['pos'] = '<a href="index.php" target="_self">首页</a>';
$GLOBALS['title'] = '图书管理系统 - 首页';

//退出动作
if(isset($_GET['action']) && $_GET['action'] == 'logout')
{
	$_SESSION = array();
	if(isset($_COOKIE[session_name()]))		//销毁保存在客户端的session_id
	{
		setcookie(session_name(), '', time()-1, '/');
	}
	$mysql->msg('index.php', '退出成功，欢迎您再次登录！');
}

$hotbooks = $action->_get_hot_books(5);	//读取热门图书
$tuijian  = $action->_get_tuijian(5);	//读取推荐图书
$click    = $action->_get_click(5);		//读取点击排行
$newbooks = $action->_get_new_books(4); //读取最新图书
$hotclick = $action->_get_click(4); 	//读取热门点击
$topbtype = $action->_get_class();		//读取所有分类
?>
<?php include('public/top.php');//引入头?>	
<div class="left">
  <div class="left1">
    <h1>热门借阅</h1>
    <ul>
    <?php
	if(!empty($hotbooks))
	{
    	foreach($hotbooks as $v)
		{
			echo '<li><a href="book_view.php?bookid=' . $v['bid'] . '">' . $v['name'] . '</a><em><img src="style/image/hot.gif" /></em></li>';
		}
	}
	else
	{
		echo '<li>暂无图书</li>';
	}
	?>
    </ul>
    </div>
  <div class="left1">
    <h1>推荐图书</h1>
    <ul>
    <?php
	if(!empty($tuijian))
	{
		foreach($tuijian as $val)
		{
    		echo '<li><a href="book_view.php?bookid=' . $val['bid'] . '">' . $val['name'] . '</a><em><img src="style/image/tuijian.gif" /></em></li>';
		}
	}
	else
	{
		echo '<li>暂无图书</li>';
	}
	?>
    </ul>
    </div>
  <div class="left1">
    <h1>总点击排行</h1>
    <ul>
    <?php
	if(!empty($click))
	{
		foreach($click as $v)
		{
			echo '<li><em>' . $v['click'] . '次</em><a href="book_view.php?bookid=' . $v['bid'] . '">' . $v['name'] . '</a></li>';
		}
	}
	else
	{
		echo '<li>暂无图书</li>';
	}
	?>
    </ul>
    </div>
</div>
<div class="right">
  <form action="search.php" method="post">
  <div class="searchbar"><b>搜索图书：</b>
    <input type="text" name="search" value="搜搜看" class="searchtext" />
    <select name="type">
    	<option value="name">图书名称</option>
    	<option value="pstore">按出版社</option>
    	<option value="typeid">图书分类</option>
    </select>
    <input type="submit" name="sbtn" class="sbtn" value="搜索" />
  </div>
  </form>
  <!--搜索框-->
  <div class="rbookc">
    <h2>图书分类</h2>
    <div class="field">
    <ul>
    <?php
	if(!empty($topbtype))
	{
		foreach($topbtype as $v)
		{
			echo '<li><a href="book_by_class.php?typeid=' . $v['id'] . '" title="' . $v['description'] . '">' . $v['value'] . '</a>';
			echo '<i>(' . $v['counts'] . ')</i></li>';
		}
	}
	else
	{
		echo '<li>暂无分类</li>';
	}
	?>
    </ul>
    <div class="clr"></div>
    <div class="jingjian">全部分类</div>
    <div class="clr"></div>
    </div>
  </div>
  <!--图书分类-->
  <div class="rnewbook">
    <h2>新书上架</h2>
    <div class="field2">
    	<dl>
        	<dd>
            	<dl>
                	<dd>图书名称</dd>
                	<dd>出版社</dd>
                	<dd>上架时间</dd>
                </dl>
            </dd>
            <?php
			if(!empty($newbooks))
			{
				foreach($newbooks as $v)
				{
			?>
            <dd>
            	<dl>
                	<dd><?php echo '<a href="book_view.php?bookid=' . $v['bid'] . '">' . $v['name'] . '</a>';?></dd>
                	<dd><?php echo $v['pstore'];?></dd>
                	<dd><?php echo d($v['indate']);?></dd>
                </dl>
            </dd>
            <?php
				}
			}
			?>
        </dl>
        <div class="clr"></div>
    </div>
  </div>
  <div class="rhot">
    <h2>热门点击</h2>
    <div class="field3">
    	<dl>
        	<dd>
            	<dl>
                	<dd>图书名称</dd>
                	<dd>出版社</dd>
                	<dd>点击量（次）</dd>
                </dl>
            </dd>
   			<?php
			if(!empty($hotclick))
			{
				foreach($hotclick as $v)
				{
			?>
            <dd>
            	<dl>
                	<dd><?php echo '<a href="book_view.php?bookid=' . $v['bid'] . '">' . $v['name'] . '</a>';?></dd>
                	<dd><?php echo $v['pstore'];?></dd>
                	<dd><?php echo $v['click'];?></dd>
                </dl>
            </dd>
            <?php
				}
			}
			?>
        </dl>
        <div class="clr"></div>
    </div>
  </div>
</div>
<?php echo $copyright;?>
</body>
</html>